home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GDEVXINI.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  31KB  |  916 lines

  1. /* Copyright (C) 1989, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gdevxini.c */
  20. /* X Windows driver initialization for Ghostscript library */
  21. #include "gx.h"            /* for gx_bitmap; includes std.h */
  22. #include "memory_.h"
  23. #include "math_.h"
  24. #include "x_.h"
  25. #include "gxdevice.h"
  26. #include "gdevx.h"
  27.  
  28. extern char *getenv(P1(const char *));
  29.  
  30. private XtResource resources[] = {
  31.     {XtNbackground, XtCBackground, XtRPixel, sizeof(Pixel),
  32.      XtOffsetOf(gx_device_X, background),
  33.      XtRString, (XtPointer)"XtDefaultBackground"},
  34.     {XtNborderColor, XtCBorderColor, XtRPixel, sizeof(Pixel),
  35.      XtOffsetOf(gx_device_X, borderColor),
  36.      XtRString, (XtPointer)"XtDefaultForeground"},
  37.     {XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
  38.      XtOffsetOf(gx_device_X, borderWidth),
  39.      XtRImmediate, (XtPointer)1},
  40.     {"dingbatFonts", "DingbatFonts", XtRString, sizeof(String), 
  41.      XtOffsetOf(gx_device_X, dingbatFonts),
  42.      XtRString, "ZapfDingbats: -Adobe-ITC Zapf Dingbats-Medium-R-Normal--"},
  43.     {"externalFontTolerance", "ExternalFontTolerance", XtRFloat, sizeof(float),
  44.      XtOffsetOf(gx_device_X, xFontTolerance),
  45.      XtRString, (XtPointer)"10.0"},
  46.     {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
  47.      XtOffsetOf(gx_device_X, foreground),
  48.      XtRString, (XtPointer)"XtDefaultForeground"},
  49.     {XtNgeometry, XtCGeometry, XtRString, sizeof(String), 
  50.      XtOffsetOf(gx_device_X, geometry),
  51.      XtRString, NULL},
  52.     {"logExternalFonts", "LogExternalFonts", XtRBoolean, sizeof(Boolean), 
  53.      XtOffsetOf(gx_device_X, logXFonts),
  54.      XtRImmediate, (XtPointer)False},
  55.     {"maxGrayRamp", "MaxGrayRamp", XtRInt, sizeof(int), 
  56.      XtOffsetOf(gx_device_X, maxGrayRamp),
  57.      XtRImmediate, (XtPointer)128},
  58.     {"maxRGBRamp", "MaxRGBRamp", XtRInt, sizeof(int), 
  59.      XtOffsetOf(gx_device_X, maxRGBRamp),
  60.      XtRImmediate, (XtPointer)5},
  61.     {"palette", "Palette", XtRString, sizeof(String), 
  62.      XtOffsetOf(gx_device_X, palette),
  63.      XtRString, "Color"},
  64.  
  65.     /* I had to compress the whitespace out of the default string to
  66.      * satisfy certain balky compilers.
  67.      */
  68.     {"regularFonts", "RegularFonts", XtRString, sizeof(String), 
  69.      XtOffsetOf(gx_device_X, regularFonts),
  70.      XtRString, "\
  71. AvantGarde-Book:-Adobe-ITC Avant Garde Gothic-Book-R-Normal--\n\
  72. AvantGarde-BookOblique:-Adobe-ITC Avant Garde Gothic-Book-O-Normal--\n\
  73. AvantGarde-Demi:-Adobe-ITC Avant Garde Gothic-Demi-R-Normal--\n\
  74. AvantGarde-DemiOblique:-Adobe-ITC Avant Garde Gothic-Demi-O-Normal--\n\
  75. Bookman-Demi:-Adobe-ITC Bookman-Demi-R-Normal--\n\
  76. Bookman-DemiItalic:-Adobe-ITC Bookman-Demi-I-Normal--\n\
  77. Bookman-Light:-Adobe-ITC Bookman-Light-R-Normal--\n\
  78. Bookman-LightItalic:-Adobe-ITC Bookman-Light-I-Normal--\n\
  79. Courier:-Adobe-Courier-Medium-R-Normal--\n\
  80. Courier-Bold:-Adobe-Courier-Bold-R-Normal--\n\
  81. Courier-BoldOblique:-Adobe-Courier-Bold-O-Normal--\n\
  82. Courier-Oblique:-Adobe-Courier-Medium-O-Normal--\n\
  83. Helvetica:-Adobe-Helvetica-Medium-R-Normal--\n\
  84. Helvetica-Bold:-Adobe-Helvetica-Bold-R-Normal--\n\
  85. Helvetica-BoldOblique:-Adobe-Helvetica-Bold-O-Normal--\n\
  86. Helvetica-Narrow:-Adobe-Helvetica-Medium-R-Narrow--\n\
  87. Helvetica-Narrow-Bold:-Adobe-Helvetica-Bold-R-Narrow--\n\
  88. Helvetica-Narrow-BoldOblique:-Adobe-Helvetica-Bold-O-Narrow--\n\
  89. Helvetica-Narrow-Oblique:-Adobe-Helvetica-Medium-O-Narrow--\n\
  90. Helvetica-Oblique:-Adobe-Helvetica-Medium-O-Normal--\n\
  91. NewCenturySchlbk-Bold:-Adobe-New Century Schoolbook-Bold-R-Normal--\n\
  92. NewCenturySchlbk-BoldItalic:-Adobe-New Century Schoolbook-Bold-I-Normal--\n\
  93. NewCenturySchlbk-Italic:-Adobe-New Century Schoolbook-Medium-I-Normal--\n\
  94. NewCenturySchlbk-Roman:-Adobe-New Century Schoolbook-Medium-R-Normal--\n\
  95. Palatino-Bold:-Adobe-Palatino-Bold-R-Normal--\n\
  96. Palatino-BoldItalic:-Adobe-Palatino-Bold-I-Normal--\n\
  97. Palatino-Italic:-Adobe-Palatino-Medium-I-Normal--\n\
  98. Palatino-Roman:-Adobe-Palatino-Medium-R-Normal--\n\
  99. Times-Bold:-Adobe-Times-Bold-R-Normal--\n\
  100. Times-BoldItalic:-Adobe-Times-Bold-I-Normal--\n\
  101. Times-Italic:-Adobe-Times-Medium-I-Normal--\n\
  102. Times-Roman:-Adobe-Times-Medium-R-Normal--\n\
  103. ZapfChancery-MediumItalic:-Adobe-ITC Zapf Chancery-Medium-I-Normal--"},
  104.     {"symbolFonts", "SymbolFonts", XtRString, sizeof(String), 
  105.      XtOffsetOf(gx_device_X, symbolFonts),
  106.      XtRString, "Symbol: -Adobe-Symbol-Medium-R-Normal--"},
  107.     {"useBackingPixmap", "UseBackingPixmap", XtRBoolean, sizeof(Boolean), 
  108.      XtOffsetOf(gx_device_X, useBackingPixmap),
  109.      XtRImmediate, (XtPointer)True},
  110.     {"useExternalFonts", "UseExternalFonts", XtRBoolean, sizeof(Boolean), 
  111.      XtOffsetOf(gx_device_X, useXFonts),
  112.      XtRImmediate, (XtPointer)True},
  113.     {"useScalableFonts", "UseScalableFonts", XtRBoolean, sizeof(Boolean), 
  114.      XtOffsetOf(gx_device_X, useScalableFonts),
  115.      XtRImmediate, (XtPointer)True},
  116.     {"useXPutImage", "UseXPutImage", XtRBoolean, sizeof(Boolean), 
  117.      XtOffsetOf(gx_device_X, useXPutImage),
  118.      XtRImmediate, (XtPointer)True},
  119.     {"useXSetTile", "UseXSetTile", XtRBoolean, sizeof(Boolean), 
  120.      XtOffsetOf(gx_device_X, useXSetTile),
  121.      XtRImmediate, (XtPointer)True},
  122.     {"xResolution", "Resolution", XtRFloat, sizeof(float),
  123.      XtOffsetOf(gx_device_X, xResolution),
  124.      XtRString, (XtPointer)"0.0"},
  125.     {"yResolution", "Resolution", XtRFloat, sizeof(float),
  126.      XtOffsetOf(gx_device_X, yResolution),
  127.      XtRString, (XtPointer)"0.0"},
  128. };
  129.  
  130. /* Define constants for orientation from ghostview */
  131. /* Number represents clockwise rotation of the paper in degrees */
  132. typedef enum {
  133.   Portrait = 0,        /* Normal portrait orientation */
  134.   Landscape = 90,    /* Normal landscape orientation */
  135.   Upsidedown = 180,    /* Don't think this will be used much */
  136.   Seascape = 270    /* Landscape rotated the wrong way */
  137. } orientation;
  138.  
  139. /* Forward references */
  140. private void gdev_x_setup_colors(P1(gx_device_X *));
  141. private void gdev_x_setup_fontmap(P1(gx_device_X *));
  142.  
  143. /* Open the X device */
  144. int
  145. gdev_x_open(register gx_device_X *xdev)
  146. {
  147.     XSizeHints sizehints;
  148.     char *window_id;
  149.     XEvent event;
  150.     XVisualInfo xvinfo;
  151.     int nitems;
  152.     XtAppContext app_con;
  153.     Widget toplevel;
  154.     Display *dpy;
  155.     int zero = 0;
  156.  
  157. #ifdef DEBUG
  158.     if (gs_debug['X']) {
  159.     extern int _Xdebug;
  160.  
  161.     _Xdebug = 1;
  162.     }
  163. #endif
  164.     if (!(xdev->dpy = XOpenDisplay((char *)NULL))) {
  165.     char *dispname = getenv("DISPLAY");
  166.  
  167.     eprintf1("gs: Cannot open X display `%s'.\n",
  168.          (dispname == NULL ? "(null)" : dispname));
  169.     exit(1);
  170.     }
  171.     xdev->dest = 0;
  172.     if ((window_id = getenv("GHOSTVIEW"))) {
  173.     if (!(xdev->ghostview = sscanf(window_id, "%d %d",
  174.                        &(xdev->win), &(xdev->dest)))) {
  175.         eprintf("gs: Cannot get Window ID from ghostview.\n");
  176.         exit(1);
  177.     }
  178.     }
  179.     if (xdev->ghostview) {
  180.     XWindowAttributes attrib;
  181.     Atom type;
  182.     int format;
  183.     unsigned long nitems, bytes_after;
  184.     char *buf;
  185.     Atom ghostview_atom = XInternAtom(xdev->dpy, "GHOSTVIEW", False);
  186.  
  187.     if (XGetWindowAttributes(xdev->dpy, xdev->win, &attrib)) {
  188.         xdev->scr = attrib.screen;
  189.         xvinfo.visual = attrib.visual;
  190.         xdev->cmap = attrib.colormap;
  191.         xdev->width = attrib.width;
  192.         xdev->height = attrib.height;
  193.     }
  194.     /* Delete property if explicit dest is given */
  195.     if (XGetWindowProperty(xdev->dpy, xdev->win, gh